﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WS.EKA.Model;
using System.Data.SqlClient;

namespace WS.EKA.DataAccess
{
    public class ShoppingCartContext:DBContext<ShoppingCart>
    {
        const string ShoppingCartAdd = "Usp_ShoppingCartAdd";
        const string ShoppingCartDelete = "Usp_ShoppingCartDelete";
        public static void Add(ShoppingCart product)
        {
            SqlParameter[] parameters = new SqlParameter[]
                {
                    new SqlParameter("@MemLoginID",product.MemLoginID),
                    new SqlParameter("@ProductGuid",product.ProductGuid),
                    new SqlParameter("@Attributes",product.Attributes),
                    new SqlParameter("@ExtensionAttriutes",product.ExtensionAttriutes),
                    new SqlParameter("@BuyNumber",product.BuyNumber),
                    new SqlParameter("@BuyPrice",product.BuyPrice),
                    new SqlParameter("@IsJoinActivity",product.IsJoinActivity),
                    new SqlParameter("@IsPresent",product.IsPresent)
                };

            ExecProc(null,ShoppingCartAdd, parameters);
        }

        public static void Update(ShoppingCart product)
        {
            string sql = @" UPDATE ShopNum1_Cart SET BuyNumber = @BuyNumber
                            WHERE MemLoginID=@MemLoginID AND ProductGuid=@ProductGuid";
            SqlParameter[] parameters = new SqlParameter[]
                {
                    new SqlParameter("@MemLoginID",product.MemLoginID),
                    new SqlParameter("@ProductGuid",product.ProductGuid),
                    new SqlParameter("@BuyNumber",product.BuyNumber)
                };

            ExecSQL(sql, parameters);
        }

        public static void Delete(string loginId, Guid productId)
        {
            SqlParameter[] parameters = new SqlParameter[]
                {
                    new SqlParameter("@MemLoginID",loginId),
                    new SqlParameter("@ProductGuid",productId)
                };

            ExecProc(null,ShoppingCartDelete, parameters);
        }
    }
}
